// JavaScript Document
/*自己写的配置文件  调用方法*/

/*
用KindEditor 替换 textarea 方法 ： 在textarea标签身上 加上 KindEditor属性 
例如： <textarea name="body1" kindeditor style="width:800px;height:400px;visibility:hidden;">KindEditor</textarea>
*/
(function(){
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[KindEditor]', {
					allowFileManager : true ,
					colorTable : [
['#000000', '#E56600', '#64451D', '#DFC5A4', '#FFE500', '#009900', '#006600', '#99BB00'],
['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE', '#666666', '#6666ff'],
['#E53333', '#993300', '#333300', '#003300', '#003366', '#000080', '#333399', '#333333'],
['#800000', '#FF6600', '#808000', '#008080', '#0000FF', '#666699', '#CCFFFF', '#CCFFCC'],
['#FF0000', '#FF9900', '#99CC00', '#339966', '#33CCCC', '#3366FF', '#800080', '#99CCFF'],
['#FF00FF', '#FFCC00', '#FFFF00', '#00FF00', '#00FFFF', '#00CCFF', '#993366', '#CC99FF'], 
['#FF99CC', '#FFCC99', '#FFFF99', '#808080', '#999999', '#C0C0C0', '#CCCCCC', '#FFFFFF']],
					//afterBlur: function () { this.sync(); }
					afterChange: function () { this.sync(); }
				});
			});
})();
/*
图片上传
DOM:
        <div kindeditor="uploadpic" >
        	<img src="" KEimg style="max-width:100px; max-height:100px;" >
            <input type="text" name="pic" value="123" KEipt/>
            <input type="button" value="图片上传" KEbtn >
        </div>
		
		
		不能修改的  整体 kindeditor="uploadpic"  KEimg   KEipt  KEbtn

*/
(function(){

			KindEditor.ready(function(K) {
				var editor = K.editor({
					allowFileManager : true,

				});
				var box = K('[kindeditor=uploadpic]');
				box.each(function(){
					var $that = this;
					var $img = K.query('[KEimg]',$that);
					var $ipt = K.query('[KEipt]', $that);
					var $btn = K.query('[KEbtn]', $that);

					K($btn).click(function() {
						editor.loadPlugin('image', function() {
							editor.plugin.imageDialog({
								showLocal : true, //允许本地上传  true | false
					  			showRemote : true,//允许网络图片  true | false
								imageUrl : K($ipt).val(),
								clickFn : function(url, title, width, height, border, align) {
									K($ipt).val(url);
									
									try{$($ipt).blur();}catch(e){}
									
									K($img).attr('src',url).show();
									editor.hideDialog();
								}
							});
						});
					});
						  
				});
			});
})();

/*
拾色器

        <div kindeditor="colorpicker" >
        	<span KEbg >&nbsp;</span>
            <input type="text" name="color" value="" KEipt/>
            <input type="button" value="选择颜色" KEbtn >
        </div>
		
		
*/
(function(){
			KindEditor.ready(function(K) {
									  
				var colorpicker;//拾色器
				var box = K('[kindeditor=colorpicker]');
				box.each(function(){
					var $that = this;
					var $bg = K.query('[KEbg]',$that);
					var $ipt = K.query('[KEipt]', $that);
					var $btn = K.query('[KEbtn]', $that);

					
					K($btn).bind('click', function(e) {
						e.stopPropagation();//阻止冒泡
						if (colorpicker) {
							colorpicker.remove();
							colorpicker = null;
							return;
						}
						var colorpickerPos = K($btn).pos();
						colorpicker = K.colorpicker({
							x : colorpickerPos.x,
							y : colorpickerPos.y + K($btn).height(),
							z : 19811214,
							selectedColor : 'default',
							noColor : '无颜色',
							colors:[
['#000000', '#E56600', '#64451D', '#DFC5A4', '#FFE500', '#009900', '#006600', '#99BB00'],
['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE', '#666666', '#6666ff'],
['#E53333', '#993300', '#333300', '#003300', '#003366', '#000080', '#333399', '#333333'],
['#800000', '#FF6600', '#808000', '#008080', '#0000FF', '#666699', '#CCFFFF', '#CCFFCC'],
['#FF0000', '#FF9900', '#99CC00', '#339966', '#33CCCC', '#3366FF', '#800080', '#99CCFF'],
['#FF00FF', '#FFCC00', '#FFFF00', '#00FF00', '#00FFFF', '#00CCFF', '#993366', '#CC99FF'], 
['#FF99CC', '#FFCC99', '#FFFF99', '#808080', '#999999', '#C0C0C0', '#CCCCCC', '#FFFFFF']],
							click : function(color) {
								K($ipt).val(color);
								K($bg).css('background',color);
								colorpicker.remove();
								colorpicker = null;
							}
						});
					});
					K($ipt).bind('change', function() {
						var color = K($ipt).val();
						K($bg).css('background',color);
					});
				});
				K(document).click(function() {
					if (colorpicker) {
						colorpicker.remove();
						colorpicker = null;
					}
				});
				
				
			});
		  
})()


